answersLogoWhite

0

Compare While with for Statements

Updated: 10/23/2022
User Avatar

Tosu

Lvl 1
12y ago

Best Answer

The while loop is the more general one because its loop condition is more flexible and can be more complicated than that of a for loop. The condition of a for loop is always the same and implicit in the construction. A for loop stops if there are no more elements in the collection to treat. For simple traversals or iterations over index ranges it is a good advice to use the for statement because it handles the iteration variable for you, so it is more secure than while where you have to handle the end of the iteration and the change of the iteration variable by yourself.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Compare While with for Statements
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Compare and contrast vision statements with mission statements?

Type your answer here... vision is long term goal of an organization while as mission is short step to achieve the vision


Compare and contrast vision statements with mission statements in terms of composition and importance?

uuyfhujgjkg


Compare and contrast vision statements with mission statements in terms of composition and importance.?

uuyfhujgjkg


What is Difference between if statement and select case statement in vbscript?

If statements and Select-Case statements are two similar features that allow for code branching. The difference is that each If statement may compare against different variables and different ranges, while Select-Case statements may only compare against one variable at a time, and must compare against discrete values. Select-Case is therefore a specialized form of If statements, and are more efficient in terms of amount of code used and execution speed when used instead of theequivalentIf-Else statements.


What are iterative statements?

An iterative statement is a looping statement, such as a 'for', 'while', or 'do-while' statement. They cause statements to be repeated (iterated) multiple times.


What includes the horizontal analysis of comparative statement?

In Horizontal analysis of statements companies tries to compare its financial statements with competitors to see that how well or bad they have performed.


What is the difference between do while and while?

In while, from the very first term, every time, the related conditions in while will be checked and then the statements will execute. But, in do-while, all the statements under do will execute once and then compiler will check the while condition. Therefore, only first time only statements will execute without checking the conditions in while, but not from the second term repetition. written by DILSHAN MADUSANKA dilshanmadusanka@yahoo.com


Compare Do-While with While Statements?

A Do-While loop looks like this: do { loop body } while (condition); and a While loop looks like this: while (condition) { loop body } The main difference is that the loop body is always run once in the Do-While loop, then the condition is checked to see if the loop should keep running. In a While loop, the condition is checked first, and it will not run the loop body at all if the condition is false.


What are the statements that appear between the while and the end while clauses called?

Body of the loop


What are eterative statements?

Iterative statements are:while (expr) statementfor (expr; expr; expr) statementdo statement while (expr);


What is a while?

The while keyword is used to create a while loop, which tests a boolean expression and executes the block of statements associated with the loop.If the expression evaluates to true, this continues until the expression evaluates to false.This keyword can also be used to create a do-while loop.Syntax:do{statements;}while(condition);


Explain control instructions in c plus plus?

Control instructions are instructions that alter the flow of execution. In C++ this include if, if-else statements, switch-case statements and the conditional ternary operator (?:), as well as loop structures (for, while, do-while) and procedural goto statements.