From Gates to Apps: An Introduction to Computer Science by Edward Amoroso & Matthew Amoroso
Author:Edward Amoroso & Matthew Amoroso
Language: eng
Format: azw3
Published: 2017-07-13T07:00:00+00:00
Example: Use a for-loop to write a small snippet of code to zero out an integer array A with length ten.
Answer: The code snippet is as follows:
for index = 1 to 10 do
A[index] = 0
od
A common way to use for-loops is to examine strings. If you recall, strings are groups of individual characters that make up meaningful words and phrases to humans, but not to computers. Using for-loops to examine each individual character of a string can give the string meaning to the computer.
For example, a website that requires certain criteria for passwords, (at least one letter, symbol, number, etc.) may utilize for-loops to do this. Like our previous examples of for-loops, this code would execute commands as many times as a certain index tells it to. In the above code, this index is an array with length 10, but in a password analyzing for-loop the index would be the actual password, or string.
Another loop construct is called a while-loop. This works in a similar manner, but rather than counting out an index in advance, the while-loop tests some condition at the end of the loop to determine whether to continue, or repeat another round of the loop. Here’s an example:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Art of Coaching Workbook by Elena Aguilar(50065)
Trainspotting by Irvine Welsh(20975)
Twilight of the Idols With the Antichrist and Ecce Homo by Friedrich Nietzsche(18279)
Fangirl by Rainbow Rowell(8771)
Periodization Training for Sports by Tudor Bompa(7895)
Change Your Questions, Change Your Life by Marilee Adams(7336)
This Is How You Lose Her by Junot Diaz(6411)
Asking the Right Questions: A Guide to Critical Thinking by M. Neil Browne & Stuart M. Keeley(5334)
Grit by Angela Duckworth(5275)
Red Sparrow by Jason Matthews(5176)
Paper Towns by Green John(4769)
Room 212 by Kate Stewart(4716)
Ken Follett - World without end by Ken Follett(4425)
The Sports Rules Book by Human Kinetics(4058)
Housekeeping by Marilynne Robinson(4039)
Double Down (Diary of a Wimpy Kid Book 11) by Jeff Kinney(3893)
Papillon (English) by Henri Charrière(3886)
Exercise Technique Manual for Resistance Training by National Strength & Conditioning Association(3765)
The Motorcycle Diaries by Ernesto Che Guevara(3764)
