r/Basic • • Nov 06 '22

Basic Anywhere If statement issue?

Users of the Basic Anywhere Machine,

Basic Anywhere is complaining that my final end if is not matched.

print "Colatz Conjecture "
do
	input "Starting Number :";n
	if (n > 1) then   (THIS IS THE IF STATEMENT THAT GOES WITH THE END IF BELOW)
		limit = n
		limitat = 0
		top = n
		steps = 0
		do
			if (n/2 = int(n/2)) then
				n = n / 2
			else
				n = 3 * n + 1
			end if
			
			steps = steps + 1
			
			if (n < limit and limitat = 0) then
				print
				print "Limit Met at : ";steps
				limitat = steps
			end if
			
			print n;
			
			if n > top then
				top = n
			end if
			
		while n>1
		
		print
		print
		print "Report for      :";limit
		print " Steps          :";steps
		print " Limit Met      :";limitat
		print " Max reached    :";top
		
	end if   (THIS IS THE ONE I GET THE ERROR ON)
while n>0
end

See shouting caps in program for the matched if / end-if - btw sorry for the shouting. The parenthesized markers are not part of the code.

Where am I going wrong? I have an end if for every if statement.

1 Upvotes

20 comments sorted by

View all comments

Show parent comment

1

u/CharlieJV13 Nov 06 '22

I can't speak for you, but me: I gave up counting the ways I can mess anything up eons ago. I put a positive spin on it by saying I'm an artsy-creative type.

Running the program, I'm thinking: "I've seen this before recently."

Rosetta Code! ("Hailstone sequence") https://rosettacode.org/wiki/Hailstone_sequence#:~:text=The%20(unproven)%20Collatz%20conjecture%20is,2%20mapping%2C%203n%20%2B%201%20problem

You'll find the GW-BASIC version of that program in BASIC Anywhere Machine. I've been mostly focused on GW-BASIC (reasonable) compatibility for the better part of the last 4 months. (That version when BAM did not yet support vertical scrolling when PRINTING beyond the bottom of the console window.)