0% found this document useful (0 votes)
6 views8 pages

Loops Ass

Uploaded by

devmaqib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

Loops Ass

Uploaded by

devmaqib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

Purpose of Loop:

"To iterate over a list of items to access, analyze and return


affected specific item"
=====>Control Structure (Refers to the Construct to perform
iterative execution behaviour to optimize processing)
Generic Properties of Loop:
1- Initial Counter Variable
2- Condition to Iterate
3- Incrementation
4- Case-Sensitive for keyword
5- Use of break and continue keyword
6- Nesting

COMPARISON SECTION:
Variants in JAVA:
Example of For-Each Variant in Java for arrays and
collections (lists or sets):

In C++, we have same formats for while, for and do while


loops that we use for implementing control structure in
execution. Except that of For-Each which is a innovation and
enhancement included in Java and some other languages. We
will take a look on them.

In Python, we use in keyword with loops which checks specific


word in specific data structures.
For counting purposes, we use range(value) function for limiting
iterations.
On the other hand, we iterate over lists[], tuples(), and strings.

Using range f(x) with nesting for loops:


We can exit the loop prematurely, if some kind of condition
evaluates true,
We use break keyword for this in every high level language like
C++, Java, JS, Python etc.
In python;

For, ignoring entire block on a specific condition containing


further lines of code to execute; we use continue keyword,

We can also iterate over dictionaries to check key and values


simultaneously in python;
List Comprehensions is a specific Python variant for looping;

Above, x power 2 is applied on every mutated value of x and all


values will return in squares list.
In Javascript, we can also use in keyword with for looplike in
python but in more traditional way. It is a tradition-bounded
variant in the world of for loops.

We can use the same break and continue statements in loops to


intervene loop control.
Like in Java, JS has also offered a new variant of For-Loop with
a more efficient and different style. It is like a method attatched
to some data structure take call back function or each item in
array to perform specific functionalities on each of them.

Here the call back function is javascript arrow function. We can


use simple one also.
Lastly, for-of loop specific and distinctive variant is offered in
JS.
As we know, that we use for-in whenever we want to iterate
using enumerable properties of an object such as keys. On the
other hand, we use for-of whenever we want to iterate over the
values of an iterable object (like arrays, strings, Maps, Sets, etc.)
Just see the difference on arrays;
Real Time:

You might also like