For and While loops: differences, question, and reasons -


I am trying to understand some of the answers to some questions and to loops in C ++ and among its causes And some differences? Even I've come so far along. According to

: While (expression) statement

and for this: (initial; condition; increase) statement;

For the loop, there is the initialization, where do we declare the variable to be used in condition statement?

What is the situation, it will be a loop.

There is an increase where we decide how much addition or subtraction it is in the variable.

While loop expression is also a condition right? Or are they completely different words in this case?

I saw that with loop, I can move the part of the growth into the statement if I want but I can not do it while declaring a variable in parentheses or parentheses in the loop (which is loop Is an introductory thing to do). What kind of am I curious, what is the reason?

Anyway, I'm reading with the help of Google and advising people, I am absolutely new to programming, please take it easy on me, I have yet to have jargon or complex answers I am not up to date :) Please tell me if you need more information or anything.

for loops is more of a feature that builds a true language . For example, for the loop, it can be easily expanded in the while loop.

For (c = 0; c <+ 10; c ++) is equal to

  c = 0; While (c & lt; 10) {// some details C ++; }  

In addition, are not limited to simple numerical functions for loops, you can do such complex things (syntax): // A very basic linked list node straight node {struct node * next; }; Structure node; // 'node' for // (node ​​= start; node; node = node-> next) {} ) // node our node on all nodes from the beginning ( Not declared in this sample) P> which will be repeated on a simple linked list.

You may also have many preliminary, terms and statements (depending on the language): for (c = 0, d = 5; c <10, d & lt; 20 ; C ++, d ++) . But I recommend this kind of loops for the mad because they are messy.


Comments