CSC108H1 Study Guide - Midterm Guide: Collatz Conjecture, Infinite Loop, Boolean Expression

82 views2 pages
29 Oct 2015
School
Course
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

It all depends on the problem you are trying to solve. In most cases, you can use any of the two. Here are a few guidelines to keep in mind: (1) for-loops work in scenarios where you know (or can compute) the number of iterations your loop will execute, before you enter the loop. In some scenarios though, you might need to do some extra work in the while-loop case to make the two equivalent. Think of the simple example where we ask you to print every character of a string. Write both the for-loop and the while-loop code and compare them. (3) if you cannot compute an upper bound on the number of your iterations, then you need to use a while-loop. While loops are the perfect candidate when what you do in the body of the while-loop determines the number of iterations.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers

Related Documents

Related Questions