Computer science nested loop problem

In summary, the conversation is about a student struggling with a question on their exam review. They are using a programming language called Turing and are trying to produce a specific output using nested loops. They have attempted multiple solutions but have not been successful.
  • #1
w3tw1lly
21
0

Homework Statement


This is for exam review but this question is the only one I havn't gotten. I just got this tonight and the exam is tommorow and I can't ask the teacher for the solution. The language we are using is turing but I don't think that should matter.

d) Use a nested loop to produce the following output.

#
?#
??#
?#
??#
?#
#



Homework Equations


N/A


The Attempt at a Solution


All my attempts looked close but when I began thinking about them they were off quite a bit.
 
Physics news on Phys.org
  • #2
loop i:=1 step 1 until 3 loop j:=1 step 1 until 3 if (i+j) mod 3 = 0 then put "?" else put "#" end if end loop put ""end loop
 
  • #3


I can understand the frustration of not being able to ask your teacher for the solution and having limited time to prepare for an exam. However, it is important to remember that cheating is not a viable solution and will only harm your academic progress in the long run.

Instead, I would suggest breaking down the problem into smaller parts and tackling them one at a time. Firstly, try to understand the concept of nested loops and how they work. This will help you in solving similar problems in the future.

Next, try to visualize the output you want to achieve and think of the steps needed to reach that output. You can also try writing out the steps in pseudocode or drawing a flowchart to help you organize your thoughts.

Once you have a clear understanding of the problem and a plan of action, start coding and testing your solution. If you encounter any errors or difficulties, don't hesitate to seek help from online resources or classmates who may have a better understanding of the topic.

Remember, as a scientist, it is important to have a strong foundation in problem-solving and critical thinking. Don't be discouraged by this challenge and use it as an opportunity to improve your skills. Good luck on your exam.
 

Related to Computer science nested loop problem

1. What is a nested loop in computer science?

A nested loop in computer science is a programming technique where a loop is placed inside another loop. This allows for the repeated execution of a block of code in a specific pattern.

2. Why are nested loops used in computer science?

Nested loops are used in computer science to iterate through multi-dimensional data structures, such as arrays or matrices. They also allow for the execution of more complex algorithms that require multiple iterations.

3. How do you write a nested loop in computer science?

To write a nested loop in computer science, you would first declare the outer loop and then within that loop, declare the inner loop. The inner loop will execute its code for each iteration of the outer loop.

4. What are some common errors when using nested loops?

Some common errors when using nested loops include infinite loops, where the loops never terminate, and off-by-one errors, where the loop does not execute the correct number of times. These errors can be avoided by carefully planning and testing the loops.

5. Can nested loops be used for any type of problem?

While nested loops can be used for many types of problems in computer science, they may not always be the most efficient solution. It is important to consider other programming techniques and algorithms when solving a problem to determine the best approach.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • STEM Academic Advising
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • STEM Academic Advising
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
23
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
4K
  • Programming and Computer Science
Replies
29
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top