according to my teacher, a for-loop always executes at least once, even if the problem is no met.

You are watching: Which type of loop will always execute its code at least once?

Example (like I understand it indigenous C++):

for (int i=6; ns According to her, this loop would execute at least once, however it go not, or to be I absent something? Is there any kind of case, no matter what language, wherein this would certainly execute once? To eliminate the assumed in advance: yes, the was around for loops, not do-while-loops.

Edit:

Thanks for all those rapid answers, i guess this case is currently closed. Have actually a nice day/night.


c++ loops for-loop language-agnostic
re-superstructure
boost this inquiry
follow
edited Jul 5 "17 in ~ 17:44
Klaus9090
inquiry Jul 5 "17 in ~ 17:16
*

Klaus9090Klaus9090
13311 gold badge11 silver- badge55 bronze title
17
| present 12 an ext comments

4 answer 4


energetic oldest Votes
19
You can say a for-loop is constantly evaluated at least once.

But if a for-loop"s problem is not met, that block will never ever execute.

Because friend didn"t ask around other loops, i won"t attend to those.


re-publishing
boost this prize
monitor
edited Feb 23 "19 in ~ 21:20
reply Jul 5 "17 at 17:21
*

NonCreature0714NonCreature0714
4,64077 gold badges2828 silver badges5050 bronze badges
1
add a comment |
6
A loop will only execute while its condition is true. Because a because that loop and a when loop both examine the condition before the human body is executed they will never ever execute if the condition is false.

The only loop that will certainly is a carry out while loop. V a do while loop the condition is no evaluated until the end of the loop. Due to the fact that of the a perform while loop will always execute at least once.


share
improve this prize
follow
edited Feb 23 "19 in ~ 17:16
*

Stephen Kennedy
17.7k2121 yellow badges8686 silver badges105105 bronze badges
answer Jul 5 "17 at 17:22
*

NathanOliverNathanOliver
156k2727 yellow badges244244 silver- badges344344 bronze badges
include a comment |
1
A for-loop constantly makes certain the condition is true before running the program. Whereas, a do-loop operation the regimen at least once and also then checks the condition.


re-publishing
boost this price
monitor
reply Jul 6 "17 in ~ 0:09
*

EeshaEesha
1933 bronze title
add a comment |
0
An entry controlled loop will never execute if the condition is false, however, exit managed loop will certainly execute at least once.


share
improve this prize
monitor
answer Jul 5 "17 in ~ 17:25
Rajeev SinghRajeev sink
3,23222 yellow badges1616 silver- badges2828 bronze badges
add a comment |

your Answer


Thanks because that contributing solution to stack Overflow!

Please be sure to answer the question. Administer details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; ago them increase with referrals or an individual experience.

To learn more, check out our tips on writing great answers.

See more: What Element Has 5 Protons 6 Neutrons And 5 Electrons


Draft saved
Draft discarded

Sign up or log in in


sign up making use of Google
authorize up using Facebook
sign up utilizing Email and Password
submit

Post together a guest


surname
email Required, but never shown


Post as a guest


surname
email

Required, but never shown


write-up Your answer Discard

By click “Post her Answer”, you agree come our regards to service, privacy policy and also cookie plan


Not the price you're spring for? Browse other questions tagged c++ loops for-loop language-agnostic or ask your own question.


The Overflow Blog
Upcoming events
Featured top top Meta
Linked
1
Can I search in an empty array?
associated
1965
Why is making use of "for...in" for range iteration a poor idea?
4366
Accessing the index in 'for' loops?
3261
exactly how do ns loop v or enumerate a JavaScript object?
1713
how to loop through a plain JavaScript object through the objects as members
905
A 'for' loop to iterate over an enum in Java
3569
Loop through selection in JavaScript
5166
For-each over selection in JavaScript
2159
just how does PHP 'foreach' in reality work?
1772
photo Processing: Algorithm advancement for 'Coca-Cola Can' acknowledgment
1530
instead of a 32-bit loop respond to with 64-bit introduce crazy performance deviations through _mm_popcnt_u64 top top Intel CPUs
warm Network inquiries much more hot inquiries

concern feed
subscribe to RSS
concern feed To i ordered it to this RSS feed, copy and also paste this URL right into your RSS reader.


lang-cpp
stack Overflow
assets
company
stack Exchange Network
site style / logo © 2021 ridge Exchange Inc; user contributions licensed under cc by-sa. Rev2021.10.22.40552


Stack Overflow works best with JavaScript allowed
*

her privacy

By clicking “Accept every cookies”, girlfriend agree stack Exchange deserve to store cookie on your an equipment and disclose information in accordance v our Cookie Policy.