ATIKA SCHOOL
  • Home
    • JOBS IN KENYA AND ABROAD FOR KENYANS AND BEYOND
    • How its Done
    • KNEC Portal
    • Atika School Advanced Search
    • News and Opinions
    • Academic Environment
    • KNEC KCSE PROJECT INSTRUCTIONS
    • SITEMAP
    • About Us? >
      • About Us
      • Learn more about us
  • OUR PRODUCTS
    • All Categories >
      • Category
      • FREE NOVELS >
        • COURSE BOOKS
        • KCSE KISWAHILI SETBOOKS
        • Backed Up Files and Archives
        • FREE DOCUMENTS
        • PRIMARY 8-4-4 BASED RESOURCES
        • STANDARD 8 RESOURCES
        • HIGH SCHOOL RESOURCES >
          • Biology Paper 3 Exams
          • Secondary Examinations
        • PRIMARY CBC BASED RESOURCES
        • COLLEGE & VARSITY RESOURCES
    • PRIMARY RESOURCES CBC
    • PRIMARY RESOURCES 8-4-4
    • SECONDARY RESOURCES
    • NOTES & TUTORIALS
    • COLLEGE RESOURCES
    • NOVELS and OTHER BOOKS
  • EXAMINATIONS
    • PRIMARY EXAMS >
      • Primary Assignments and Random Exams
      • CBC
      • 8-4-4
      • STANDARD 8 PAST PAPERS 8-4-4 BASED
    • MOCKS AND JOINT EXAMS >
      • FORM 1 QUESTION PAPERS, ANSWERS AND MARKING SCHEMES COLLECTIONS
      • FORM 2 QUESTION PAPERS, ANSWERS AND MARKING SCHEMES COLLECTIONS
      • FORM 3 EXAMINATIONS, QUESTION PAPERS AND ANSWERS
      • MOCKS PAST EXAMS BY REGION
    • KCPE >
      • KCPE BY YEAR >
        • KCPE 2020 RESULTS, REPORTS, QUESTIONS AND ANSWERS
        • KCPE PAST PAPERS 2019 REPORTS, RESULTS, QUESTIONS AND ANSWERS
      • KCPE PAST PAPERS PER SUBJECT
      • KCPE PAST PAPERS AND ANSWERS
      • KCPE MATHEMATICS TOPICAL QUESTIONS FROM 1989 TO LAST YEAR
    • KCSE >
      • KCSE BY YEAR >
        • KNEC KCSE PAST PAPERS, MARKING SCHEMES, QUESTIONS & ANSWERS
      • KCSE BY SUBJECT >
        • KCSE PAST PAPERS BY SUBJECT
        • Free KCSE Past Papers Mathematics
        • Free KCSE Biology Questions and Answers
    • QUESTIONS & ANSWERS >
      • SECONDARY >
        • LANGUAGES >
          • A DOLL'S HOUSE BY HENRIK IBSEN RESOURCES
        • TECHNICALS >
          • COMPUTER STUDIES >
            • COMPUTER STUDIES Q & A
            • kcse computer studies paper 2 AND 3 Questions & Answers
          • BUSINESS STUDIES QUESTIONS & ANSWERS
          • KCSE AGRICULTURE TOPICAL QUESTIONS AND ANSWERS
          • KCSE HOME SCIENCE DIRECT QUESTIONS AND ANSWERS
        • SCIENCES >
          • KCSE Mathematics Topical Questions
          • KCSE Biology Topical Questions and Answers
          • CHEMISTRY TOPICAL QUESTIONS AND ANSWERS
          • KCSE Physics Topical Questions
          • KCSE physics Practical Sample Quiz
        • HUMANITIES >
          • ISLAMIC RELIGIOUS EDUCATION (IRE) QUESTIONS AND ANSWERS
          • KCSE History Topical Questions and Answers
          • GEOGRAPHY TOPICAL QUESTIONS AND ANSWERS
      • PRIMARY >
        • Standard 4-8 Mathematics Topical Questions from Mocks and KCPE
        • Std 6 Mathematics Notes
  • TUTORIALS
    • SECONDARY >
      • SCIENCES >
        • FOCUS MATHEMATICS TUTORIALS AND EXAMS FREE
        • KCSE BIOLOGY NOTES
        • FREE KCSE CHEMISTRY NOTES
        • KCSE PHYSICS NOTES, AUDIOVISUALS AND MORE
      • LANGUAGES >
        • ENGLISH >
          • English KCSE Set Books
          • ENGLISH POETRY QUESTIONS WITH ANSWERS FOR K.C.S.E CANDIDATES
          • ENGLISH GRAMMAR #KCSE
        • CHOZI LA HERI - MWONGOZO
        • KIGOGO - MWONGOZO
        • USHAIRI MASWALI NA MAJIBU
        • MASWALI NA MAJIBU YA TUMBO LISILOSHIBA
        • KCSE Kiswahili Fasihi
      • TECHNICALS >
        • HOME SCIENCE NOTES
        • KCSE BUSINESS STUDIES NOTES
        • COMPUTER STUDIES NOTES LATEST
        • kcse Computer Studies Notes
        • KCSE AGRICULTURE NOTES, SYLLABUS, QUESTIONS, ANSWERS, SCHEMES OF WORK AND OTHERS
      • HUMANITIES >
        • KCSE History Notes Form 1 to 4
        • FREE KCSE CRE NOTES
        • KCSE GEOGRAPHY NOTES
        • IRE NOTES, AUDIOVISUAL, QUESTIONS AND ANSWERS
    • PRIMARY >
      • NOTES >
        • KISWAHILI
        • SOCIAL STUDIES >
          • STANDARD 4: SOCIAL STUDIES
        • SCIENCE
        • ENGLISH >
          • KCPE and Primary Level Compositions
        • MATHEMATICS >
          • KCPE Mathematics Notes
      • EXAMINATIONS >
        • DecaTurbo Online Series Examinations
        • CBC Kiswahili
        • FOCUS A365 SERIES K.C.P.E EXAMINATIONS FOR PRIMARY
        • Standard 8 (std) English Topical Questions
    • Other Supportive Documents >
      • Free Schemes of Work
      • SYLLABUS >
        • Primary 8-4-4 based Syllabus, Objectives and Lessons
        • Primary Mathematics Syllabus
      • MASOMO VIDEOS
  • CURRICULUM
    • NEW CURRICULUM DESIGNS >
      • PRIMARY >
        • PRE PRIMARY ONE CURRICULUM WITH SYLLABUS
        • PRE PRIMARY TWO CURRICULUM WITH SYLLABUS
      • SECONDARY >
        • KNEC KCSE SYLLABUS AND COURSE OUTLINES
      • COLLEGE >
        • Regulations for the TIVET Craft and Diploma Business Examinations
  • HIGH INSTITUTIONS
    • EXAMINATIONS >
      • College and Varsity Past Papers online
    • TUTORIALS >
      • COLLEGE AND UNIVERSITY NOTES AND TUTORIALS
  • CUSTOMER CARE
    • PRICING
    • Contact
    • Help & Support
    • DONATE
    • MPESA FORM
  • BLOGS
    • ENGLISH - EKEGUSII DICTIONARY
  • MEMBERSHIP RESOURCES
    • Assignments and Random Exams
    • TERM 3 2021 PRIMARY PAST REVISION PAPERS
    • SECONDARY EXAMINATIONS
    • Search Free Documents (PDF)
  • Archived Pages
    • C.R.E (CRE) QUESTION AND ANSWERS
    • TOP SECONDARY EXAMS ALL SUBJECTS

Follow us now to receive the latest updates @schoolatika

The 'While Loop' Easy Explanation

28/8/2016

0 Comments

 

What is a While loop?

A while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement.

The while construct consists of a block of code and a condition/expression. The condition/expression is evaluated, and if the condition/expression is true, the code within the block is executed. This repeats until the condition/expression becomes false. Because the while loop checks the condition/expression before the block is executed, the control structure is often also known as a pre-test loop.

What they do is simply do a test like an if-statement, but instead of running the code block once, they jump back to the "top" where the while is, and repeat. A while-loop runs until the expression is False.

What does the while loop do?

Picture
A "While" Loop is used to repeat a specific block of code an unknown number of times, until a condition is met. For example, if we want to ask a user for a number between 1 and 10, we don't know how many times the user may enter a larger number, so we keep asking "while the number is not between 1 and 10".
​
For example, say we want to know how many times a given number can be divided by 2 before it is less than or equal to 1. If we know a specific number, such as 32, we can say 5 times, but for a given symbolic variable "NUMBER" which represents any number in the world, how many times is not known a priori (before hand). In this case, we could use a while loop to determine that answer:
The "pseudocode" for such an algorithm is: while the number is bigger than one keep dividing it by two. additionally, keep a count of how many times we do the division.

Therefore, the while loop;
  1. Like all loops, "while loops" execute blocks of code over and over again.
  2. The advantage to a while loop is that it will go (repeat) as often as necessary to accomplish its goal.

Worked example

Here is a mathlab example that can find the factorials of 10. This means 10x9x8x7x6x5x4x3x2x1
​n = 10;
f = n;
while n > 1
    n = n-1;
    f = f*n;
end
disp(['n! = ' num2str(f)])
Solution
n! = 3628800
Pseudocode
​Let n be 10
f is equal to n
while n is greater than 1
the new value of n is the old value of n less 1
new value of f is a product of the old value of f and the new value of n
endwhile
print factorial
Flowchart Extract
Picture



Print Friendly and PDF



0 Comments
Print Friendly and PDF



Leave a Reply.

    COMPUTER STUDIES QUESTIONS AND ANSWERS

    Categories

    All
    1998
    1999
    2000
    2001
    2002
    2003
    2004
    2005
    2006
    2007
    2008
    2009
    2010
    2011
    2012
    2013
    2014
    2015
    2016
    2017
    2018
    2019
    2020
    Analogue And Digital Systems
    Applications Areas Of Ict
    Areas-where-computers-are-used
    Auxiliary Storage Devices
    Basic-computer-set-up-and-cabling
    Binary Addition
    Binary Subtraction
    Career Opportunities In ICT
    Classification Of Computers
    Classification-of-computers
    Coaxial Cables
    COMPACT DISK
    COMPLETE PAPERS
    Computer Crimes
    Computer-files
    Computer Memory
    Computer Software
    Computer Systems
    COMPUTER VIRUS
    Dashboard
    Database
    Data Collection
    Data Communication
    Data-integrity
    Data Processing
    Data Representation In A Computer
    Data Security And Controls
    Definition And Development Of Algorithm
    Definition-of-a-computer
    Desktop Publisher
    Development-of-computers
    DTP
    DVD
    Editing-and-formatting-a-word-document
    Electronic Data Processing Modes
    Elementary Programming Principles
    Errors-in-data-processing
    Evolution-of-computer-systems
    Fibre Optic Cables
    File Management Using An Operating System
    File-organization-methods
    Flowchart
    Form 1 Level
    Form 2 Level
    Form 3 Level
    Form 3 Mock Exams
    Form 4 Level
    Hands On Skills
    HARDCOPY OUTPUT DEVICES
    Hardware
    Impact Of Ict On Society
    IMPACT PRINTERS
    Information
    Input Devices
    Internet And Email
    Introduction To Computers
    Introduction To Networking And Data Communication
    ISP
    Levels-of-programming-languages
    Midterm-exams
    Mind-blowing-q-a
    Mocks
    Network-topology
    NON-IMPACT PRINTERS
    Octal
    Operating Systems
    Output Devices
    Paper 1
    Parts-of-a-computer
    PRINTERS
    Processing-devices
    Processors
    Program-construction
    Program-control-structures
    Program-design
    Program-development
    Program-documentation
    Protocols
    Registers
    Review Questions
    Revision-kits
    Secondary Storage Media
    Section A
    Section B
    Security Threats And Control Measures
    Software
    Spreadsheets
    Stages Of System Development
    Storage Devices
    Symbolic-representation
    System-design
    System Development
    System-documentation
    Term-1
    The Computer Laboratory
    The-cpu
    The Keyboard
    Types Of Computer Files
    Types-of-networks
    User Interface
    Uses-of-computers
    Word Processors
    Worksheet-formatting

    Archives

    December 2024
    April 2022
    January 2022
    December 2021
    November 2021
    July 2021
    March 2021
    February 2021
    January 2021
    December 2020
    October 2020
    April 2020
    February 2020
    October 2019
    August 2019
    July 2019
    April 2019
    March 2019
    November 2018
    August 2018
    July 2018
    December 2017
    November 2017
    October 2017
    July 2017
    August 2016
    June 2016
    January 2016
    December 2015
    November 2015

    RSS Feed

Print Friendly and PDF

Primary Resources
  • K.C.P.E Past Papers
  • ​Pri - Primary 1 Level
  • Pri  - Primary 2 Level
  • Grade 1
  • Grade 2
  • Grade 3
  • Grade 4
  • Standard 5
  • Standard 6
  • Standard 7
  • Standard 8
  • English
  • Kiswahili
  • Social Studies
  • Science
  • Mathematics
  • Kenya Sign Language
  • I.R.E
  • ​H.R.E
  • Notes
  • Termly Questions
  • Mocks
  • K.C.P.E Past Papers
College Resources
  • E.C.D.E
  • P.T.E
  • D.T.E
  • Technical Diploma
  • Technical Certificate
  • Business Diploma
  • Business Certificate
  • Higher Diploma
  • K.A.S.N.E.B Resources
  • K.M.T.C Resources
  • Varsity Resources
Secondary Resources
  • K.C.S.E Past Papers
  • Form 1
  • Form 2
  • Form 3
  • Form 4
  • Term 1
  • Term 2
  • Term 3
  • English
  • Geography
  • History
  • C.R.E
  • I.R.E
  • ​H.R.E
  • Home Science
  • Computer Studies
  • Business Studies
  • Agriculture
  • Chemistry
  • Biology
  • Physics
  • Mathematics ALT A
  • Mathematics ALT B
  • Kiswahili
  • French
  • Germany
  • Arabic
  • Aviation
  • Art & Design
  • Drawing & Design
  • Building & Construction
  • Metal Works
  • Wood Work
  • Music
  • Kenya Sign Language
  • Electricity
Other Useful Links
  • Academic Environment
  • How its Done
  • News and Opinions
  • Manyam Franchise Support
  • About
  • SITEMAP
  • FOCUS A365 SERIES
  • Membership Details (KCPE/KCSE)
  • Secondary Mocks
  • SYLLABUS
Contact Us
Manyam Franchise
P.O Box 1189 - 40200 Kisii
Tel: 0728 450 424
Tel: 0738 619 279
Tel: 0763 450 425
E-mail - sales@manyamfranchise.com
Photos used under Creative Commons from wwarby, JoshMacDonald, Visual Content, wuestenigel, Homini:), Wonderlane, Mike Licht, NotionsCapital.com, The Official CTBTO Photostream, Nabor Garrido, picsaf.com, OER Africa, Jemimus, andronicusmax, Christoph Scholz, cyanocorax, matsuyuki, Mark Hodson Photos, cathyse97, tompagenet, ToGa Wanderings, crstnksslr, machernucha, panpot, ePublicist
  • Home
    • JOBS IN KENYA AND ABROAD FOR KENYANS AND BEYOND
    • How its Done
    • KNEC Portal
    • Atika School Advanced Search
    • News and Opinions
    • Academic Environment
    • KNEC KCSE PROJECT INSTRUCTIONS
    • SITEMAP
    • About Us? >
      • About Us
      • Learn more about us
  • OUR PRODUCTS
    • All Categories >
      • Category
      • FREE NOVELS >
        • COURSE BOOKS
        • KCSE KISWAHILI SETBOOKS
        • Backed Up Files and Archives
        • FREE DOCUMENTS
        • PRIMARY 8-4-4 BASED RESOURCES
        • STANDARD 8 RESOURCES
        • HIGH SCHOOL RESOURCES >
          • Biology Paper 3 Exams
          • Secondary Examinations
        • PRIMARY CBC BASED RESOURCES
        • COLLEGE & VARSITY RESOURCES
    • PRIMARY RESOURCES CBC
    • PRIMARY RESOURCES 8-4-4
    • SECONDARY RESOURCES
    • NOTES & TUTORIALS
    • COLLEGE RESOURCES
    • NOVELS and OTHER BOOKS
  • EXAMINATIONS
    • PRIMARY EXAMS >
      • Primary Assignments and Random Exams
      • CBC
      • 8-4-4
      • STANDARD 8 PAST PAPERS 8-4-4 BASED
    • MOCKS AND JOINT EXAMS >
      • FORM 1 QUESTION PAPERS, ANSWERS AND MARKING SCHEMES COLLECTIONS
      • FORM 2 QUESTION PAPERS, ANSWERS AND MARKING SCHEMES COLLECTIONS
      • FORM 3 EXAMINATIONS, QUESTION PAPERS AND ANSWERS
      • MOCKS PAST EXAMS BY REGION
    • KCPE >
      • KCPE BY YEAR >
        • KCPE 2020 RESULTS, REPORTS, QUESTIONS AND ANSWERS
        • KCPE PAST PAPERS 2019 REPORTS, RESULTS, QUESTIONS AND ANSWERS
      • KCPE PAST PAPERS PER SUBJECT
      • KCPE PAST PAPERS AND ANSWERS
      • KCPE MATHEMATICS TOPICAL QUESTIONS FROM 1989 TO LAST YEAR
    • KCSE >
      • KCSE BY YEAR >
        • KNEC KCSE PAST PAPERS, MARKING SCHEMES, QUESTIONS & ANSWERS
      • KCSE BY SUBJECT >
        • KCSE PAST PAPERS BY SUBJECT
        • Free KCSE Past Papers Mathematics
        • Free KCSE Biology Questions and Answers
    • QUESTIONS & ANSWERS >
      • SECONDARY >
        • LANGUAGES >
          • A DOLL'S HOUSE BY HENRIK IBSEN RESOURCES
        • TECHNICALS >
          • COMPUTER STUDIES >
            • COMPUTER STUDIES Q & A
            • kcse computer studies paper 2 AND 3 Questions & Answers
          • BUSINESS STUDIES QUESTIONS & ANSWERS
          • KCSE AGRICULTURE TOPICAL QUESTIONS AND ANSWERS
          • KCSE HOME SCIENCE DIRECT QUESTIONS AND ANSWERS
        • SCIENCES >
          • KCSE Mathematics Topical Questions
          • KCSE Biology Topical Questions and Answers
          • CHEMISTRY TOPICAL QUESTIONS AND ANSWERS
          • KCSE Physics Topical Questions
          • KCSE physics Practical Sample Quiz
        • HUMANITIES >
          • ISLAMIC RELIGIOUS EDUCATION (IRE) QUESTIONS AND ANSWERS
          • KCSE History Topical Questions and Answers
          • GEOGRAPHY TOPICAL QUESTIONS AND ANSWERS
      • PRIMARY >
        • Standard 4-8 Mathematics Topical Questions from Mocks and KCPE
        • Std 6 Mathematics Notes
  • TUTORIALS
    • SECONDARY >
      • SCIENCES >
        • FOCUS MATHEMATICS TUTORIALS AND EXAMS FREE
        • KCSE BIOLOGY NOTES
        • FREE KCSE CHEMISTRY NOTES
        • KCSE PHYSICS NOTES, AUDIOVISUALS AND MORE
      • LANGUAGES >
        • ENGLISH >
          • English KCSE Set Books
          • ENGLISH POETRY QUESTIONS WITH ANSWERS FOR K.C.S.E CANDIDATES
          • ENGLISH GRAMMAR #KCSE
        • CHOZI LA HERI - MWONGOZO
        • KIGOGO - MWONGOZO
        • USHAIRI MASWALI NA MAJIBU
        • MASWALI NA MAJIBU YA TUMBO LISILOSHIBA
        • KCSE Kiswahili Fasihi
      • TECHNICALS >
        • HOME SCIENCE NOTES
        • KCSE BUSINESS STUDIES NOTES
        • COMPUTER STUDIES NOTES LATEST
        • kcse Computer Studies Notes
        • KCSE AGRICULTURE NOTES, SYLLABUS, QUESTIONS, ANSWERS, SCHEMES OF WORK AND OTHERS
      • HUMANITIES >
        • KCSE History Notes Form 1 to 4
        • FREE KCSE CRE NOTES
        • KCSE GEOGRAPHY NOTES
        • IRE NOTES, AUDIOVISUAL, QUESTIONS AND ANSWERS
    • PRIMARY >
      • NOTES >
        • KISWAHILI
        • SOCIAL STUDIES >
          • STANDARD 4: SOCIAL STUDIES
        • SCIENCE
        • ENGLISH >
          • KCPE and Primary Level Compositions
        • MATHEMATICS >
          • KCPE Mathematics Notes
      • EXAMINATIONS >
        • DecaTurbo Online Series Examinations
        • CBC Kiswahili
        • FOCUS A365 SERIES K.C.P.E EXAMINATIONS FOR PRIMARY
        • Standard 8 (std) English Topical Questions
    • Other Supportive Documents >
      • Free Schemes of Work
      • SYLLABUS >
        • Primary 8-4-4 based Syllabus, Objectives and Lessons
        • Primary Mathematics Syllabus
      • MASOMO VIDEOS
  • CURRICULUM
    • NEW CURRICULUM DESIGNS >
      • PRIMARY >
        • PRE PRIMARY ONE CURRICULUM WITH SYLLABUS
        • PRE PRIMARY TWO CURRICULUM WITH SYLLABUS
      • SECONDARY >
        • KNEC KCSE SYLLABUS AND COURSE OUTLINES
      • COLLEGE >
        • Regulations for the TIVET Craft and Diploma Business Examinations
  • HIGH INSTITUTIONS
    • EXAMINATIONS >
      • College and Varsity Past Papers online
    • TUTORIALS >
      • COLLEGE AND UNIVERSITY NOTES AND TUTORIALS
  • CUSTOMER CARE
    • PRICING
    • Contact
    • Help & Support
    • DONATE
    • MPESA FORM
  • BLOGS
    • ENGLISH - EKEGUSII DICTIONARY
  • MEMBERSHIP RESOURCES
    • Assignments and Random Exams
    • TERM 3 2021 PRIMARY PAST REVISION PAPERS
    • SECONDARY EXAMINATIONS
    • Search Free Documents (PDF)
  • Archived Pages
    • C.R.E (CRE) QUESTION AND ANSWERS
    • TOP SECONDARY EXAMS ALL SUBJECTS