Re: What is the Point of Static or Constant Variables?

This is a programming 101 kind of topic, but it's actually [extremely] important in practical terms. What if, for some reason, there was a change in value? What if x needs to be 1,036,173...?
As Ethin pointed out, it would be tedious to write out a value that is longer than the variable's name that refers to it, but if a constant needs to change value for any reason, you can do this in the variable's declaration statement and have that effect pervasive throughout its lifetime.

Fizz Buzz, a popular children's game to enhance kids' understanding of division, is one common programming exercise that illustrates this point.

Write a program that counts from 1 to 100. If the number is divisible by 3, print "fizz" to the screen. If the number is divisible by 5, print "buzz" to the screen. If the number is divisible by 3 and 5, print "fizz buzz" to the screen.

Easy, right? Well, what if we wanted to abstract this to be able to handle any number ("fizz" if divisible by 2, "buzz" for 7, etc). Well, it would make more sense to use constant variables. So, if num is divisible by x, y, etc, then do etc. You'd make these constant variables so they cannot be modified or changed elsewhere in the program because that changes the logic of the program.

HTH

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : DyingMoose93 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : DyingMoose93 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector

Reply via email to