The for i loop is the greatest invention in Programming. Prove me wrong

The for i loop is the greatest invention in Programming. Prove me wrong.

Attached: 016.png (1024x768, 77K)

Functions.

Procedures.

Monads

>i
>Not iii

OOP
...
(looks both ways with shifty eyes and runs)

>useful
for
>cleaner
def (functions)

thats not a for loop, that is an iterator function that happens to use the for keyword. Notice you are not doing any boolean expressions to compare values nor are you incrementing a counter variable

What if len(names) is different from len(heights)?

You loop on the longer one.

recursion beats its ass.

that is what zip is for you giganog

higher order functions are better desu

>len names
>not checking len of heights
You could do better than this with fucking C this is disgusting

Attached: 1511451999002.jpg (711x633, 35K)

for name, height in zip(names, heights):

If you know the name and not the height, you could still say
>tower name: unknown height
but if you only know the height, you know nothing, not even what you don't know

Attached: 1514022270325.jpg (516x300, 15K)

>programming teacher stresses that you always need nested loops to go through a 2-dimensional array
>"b-but you can do that with a single loop if you really want to"
>"no user that's impossible"
>write 3 lines of code
>get a 100% grade on the condition that I never set foot in this class till the end of the semester

>mfw this is a technical university with a 200 year history

Attached: 1411874802622.png (226x207, 121K)

>can't deal with algebra
>invent an inefficient abstraction that takes 3 major releases of the language to be usable
truly a language for cucks

an iterator is just a for loop from low(array) to high(array)

I'm gonna need those write 3 lines of code. You made me curious

if you cared that much about efficiency that the tradeoff between using zip vs indexing into a list matters to you then you would not be using python, or you would at least be using something like numpy arrays + vectorization

I am willing to bet going through 100 million elements with zip vs list1[i] and list2[i] has pretty much the exact same performance in python barring memory usage.

len(A)*len(B) and modulo to index I guess

It teaches you a poorly-parallelizable concept, don't do that.

Well, yes. The whole point of that slide was it's the wrong way to do it.

oh, right, I get it
neat

Any Java fags here know the pros and cons between array list and array?

One is a list of arrays
The other isn't

nope

Attached: Screenshot_2018-06-25_20-45-46.png (649x331, 8K)

ArrayList*

int minimum=a[0,0];
for(int i=1;i

Both are arrays, but arraylist is more convenient to use.

Lmao, this'd better be sarcasm

>3 lines\ni count 5 :^)

you retard hes talking about when you access shorter[i] and it doesnt exist.

*glomps you*
;3

I thought
cin >> input
and
cout

>invention in Programming.
no, unification and backracking based prorgamming is the greatest invention/discovery in the whole programming world.

>if only the rest of the language were that simple...

I really hope you understand what >> and

you can do that in whatever language supports operator overloading, fucking retard.

GOTO master race

cache line offset padding saved programming!

>Invention
But like you can have it in ASM??

.text
Start:
mov r0, #3

Loop:
cmp r0, #0
beq end

sub r1, r1, #1
b Loop

End:
bx lr


So like is it a hardware thing???

are on ARM?

I know they're bitwise operators that have been overloaded for input and output, but that was just so neat for a beginner. you don't have to understand anything about input or output or objects or data type or any of that shit
just cin >> and cout

oldfag spotted

am ARM

>calling a for loop a "for i" loop
Is this the absolute state of script kiddies?

>I know they're bitwise operators that have been overloaded for input and output, but that was just so neat for a beginner.

no, thats the reason why pajeets and noobs writes shitty code in C++ because they don't understand what the fuck they are doing, and no they are no overloaded for input , output you brainlet

ostream& operator

it's for loops all the way down.

awww, baby python likes his frut loops.

Attached: 91eyE1a-1qL._SY445_.jpg (281x445, 40K)

meant to type bitwise shift operators, but maybe I'm wrong. nm then

Objects
[spoiler]But OOP is the worst[/spoiler]

No, conditions were the greatest invention. It's pretty easy to do a loops using only recursions.

>using only recursions.
not all languages are designed for using deep recursion and its a waste of stack.

In Python it's an object with a __iter__() method that the iter() function calls to get an object with a __next__() method that the next() function calls for every iteration of the for loop until a StopIteration exception is raised.

>__iter__()
why pytards likes to put shitty names on everything, its a fucking mess.

Sorry but nothing can top lambdas.

>nothing can top lambdas.
lambdas on non full functional languages are a meme. They are useful yes they are but they only languages where lambadas are comfi are javascript and C#

Brainlet trying to teach myself programming here. I don't get the OP pic at all. You have two arrays, names and heights, that's pretty simple. And it's a for loop, which means you execute the indented code for a specified number of iterations; in this case the length of the names array. But:

>Why use the letter "i" in particular, and what does names[i] or heights[i] mean? Is "i" just shorthand for "this iteration" and thus names[i] would be names[1], names[2] and names[3] for the first, second and third iterations, respectively?
>Why %s? Is it just shorthand for "the variables in the parenthesis, in the order they are listed"?

Use C and a proper linked list faggot

Booleans

>Why use the letter "i" in particular
Convention.
>Is "i" just shorthand for "this iteration" and thus names[i] would be names[1], names[2] and names[3] for the first, second and third iterations, respectively?
Yeah
>Why %s? Is it just shorthand for "the variables in the parenthesis, in the order they are listed"?
It's a little more complicated than that, but you're basically correct.

Note that this is a (deliberately) poorly-done example. If you want to iterate over a list (i.e., visit every element in the list) a better way to do it.

Attached: 017.png (1024x768, 63K)

Linked lists are garbage.

First class functions

Attached: blep.jpg (1024x768, 166K)

Much better:

foreach (@list) {
print "Value: $_";
}

also the ability to do this:

foreach (@list) { print $_; }

for i in `cat opisa.txt`; do echo $i; done
>fag

>what is zip
Learn how to use functions

arraylist has methods to sort and shit

C style for loop is retarded.

Read it in pseudo-English: "for i from 1 to 10".

Now read it in C/C++: "for i from 1, WHILE i is less than 10"

for (int i = 0; i < 10

There's already a while loop. K&R chapter 3.5 even says that for (expr1; expr2; expr3) {} is equivalent to expr1; while (expr2) { expr3; } and that while (expr2) loops while the expression is non-zero and stops when it's zero.

While loops are given as an example of reading from an input until the source returns nothing. For loops, the example is for counting up from 1 to 10.

It should obviously obviously be:

for (int i=0; i==10; i++)

The finishing condition should be the condition when it finishes, not the condition during while in which it continues.

(and using the C style for loop to iterate a collection in any modern language is so dumb it's literally progressing through a collection like (gif related)).

Attached: walks.gif (256x256, 91K)

>not zipping that shit
would not hire

Linked lists have no pros, only cons.

You're not going to get away with this silly user.

Except any good compiler removes that shitty loop

I taught a few bash programming tricks to my operating systems professor too. My super power was the ability to read the manual.

>The finishing condition should be the condition when it finishes, not the condition during while in which it continues.
That way you can't abuse it in numerous ways, though.

thats not the switch statement

this is not metaprogramming

That's just called a for loop you python programming prick.

its called a for each loop usually

It's called "generic for loop" (as opposed to a "numeric for loop"), you nuts.

sounds gay

But unlike OP, it isn't.

If you think this is bad look at PHP default functions

Just a fancy while loop.
Switch is a lifesaver. Saves you hundreds of redundant if checks on the same variable

It's called a for (you) loop actually.

Attached: Kate_16.12.png (1280x916, 458K)

Stack objects are better than recursion.

{ , } are unneeded

also I'm pretty sure that in C you don't even need the artificial dividing in i%x and i/x, you should be able to access all array elements sequentially.
>breaks the code
s...sorry

actually you can only nest a certain number of for loops since they need space on the return stack.

>using parallel arrays

Attached: received_1970029739681159_1.jpg (818x845, 292K)

while (i

Because you're doing it wrong.
int a[x][y] = ...;
int *p = a[0];
for(int i = 0; i < x*y; i++)
p[i];

nigga
for (@list) {print}

does the same :^)

check your object-oriented privilege

> i never gets initialized

more older i come. more often i use infinity loops

zip

do-while is better in some cases. You can start the loop before your continue condition has ever been set.

Yes, they can be useful
while(true){
___set breakCondition here;
___do stuff;
___or set breakCondition here;
___if breakCondition
______break;
}

So ugly