Question

A. What are the advantages and disadvantages of the list box? when should a list box...

A. What are the advantages and disadvantages of the list box? when should a list box be used? Describe some guidelines for when to use a list box.

B. What is the difference between a pretest and posttest Do...loop statement? give an example of each loop using pseudocode.

C. What is an infinite loop, how to avoid your program runs with an endless loop? give an example

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A.

List Box:

A list box is used in situations when there are multiple values and one or more than one value need to be selected. It is also called a pick list. It can be in the form of a pop-up window, a form, or even a dialog box.

Advantages:

1. They allow the selection of multiple items from the given list of items using shift or control key from the keyboard.

2. Better to use when you don't want the user to modify the data mentioned in the list.

Disadvantages:

  1. If the list is too large, scrolling might make you miss a few items from the list.

2. Screen space is consumed by opening a list.

3. The unordered list makes it hard to find the items.

4. Predictive or auto text is not allowed.

5. There is no text box to search for the item from a long list.

6. The selected item in the list cannot be modified.

When to use a list box:

  • A list box should be used when you have to make multiple selections.
  • It is also suitable when the number of items is less which makes access quicker.

Guidelines:

  • Write a user-friendly name for your list box.
  • The size of the list should be manageable.
  • Don't add out of the context items in a list box.

===================================================

B. Difference between a pretest and posttest Do...loop statement:

Pretest do...loop:

Pretest means the condition is tested pre-execution. If the condition is true, statements inside the loop will execute else statements will never execute.

Posttest do...loop:

Posttest means the condition is tested post-execution. This also means that statements inside the loop are executed at least once even if the condition is false.

Pseudocode for pretest do...loop:

i=1

do while i<3

       print "how are you"

       i=i+1

⇒ Here, it is tested whether ‘i’ is less than ‘3’ since the condition is true, the statement “how are you” will be printed. And then the value of ‘i’ is incremented by ‘1’. It is checked again and the statement is printed again until the value of ‘i’ becomes ‘3’ in which case statement will not be executed.

Pseudocode for posttest do...loop:

i=1

do

   print "how are you"

   i=i+1

while i==0

⇒ Here, “how are you” is printed first and then the value of ‘i’ is checked whether it is ‘0’, the condition is not true hence the loop will terminate. However, the loop statement is executed the first time even when the condition is never true.

Different between pretest and posttest loops:

1. Condition is checked at the very beginning of the loop in the pretest do loop whereas condition is checked at the very end of the loop in the posttest do loop.

2. In the pretest do...loop, if the condition is false for the first time, loop statements will never execute. Whereas in the posttest do...loop, statements will be executed at least once even if the condition is never true.

=====================================================

C. Infinite loop:

Infinite loop refers to the code which has no end or exit. This makes it repeat itself infinitely. For conditional programs, if a condition is never true, it may cause infinite execution of the program.

Avoiding an infinite or endless loop:

  • If your program has entered an infinite loop, you can press Ctrl+C on your keyboard to come out of the loop cycle.
  • Another approach to avoid getting into the infinite loop cycle is to use exception handling, where if for a given statement program enters the infinite loop it stops it from doing so and exits the program.

Example of infinite loop

  a=1

if a==1

   print "Welcome to programming"

In above program, value of 'a' is always 1, which will make the statement inside if block execute infinitely.

=====================================================

Add a comment
Know the answer?
Add Answer to:
A. What are the advantages and disadvantages of the list box? when should a list box...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT