case do problem

Tracubik affdfsdfdsfsd at b.com
Tue Mar 2 12:46:12 EST 2010


hi, i've to convert from Pascal this code:

iterations=0;
count=0;
REPEAT;
  iterations = iterations+1;
  ...
  IF (genericCondition) THEN count=count+1;
  ...
  CASE count OF:
	1: m = 1
        2: m = 10
        3: m = 100
UNTIL count = 4 OR iterations = 20

i do something like this:

iterations = 0
count = 0

m_Switch = (1,10,100)

while True:
	iterations +=1
	...
	if (genericCondition):
		count +=1
	...
	try:
		m = m_Switch[count-1]
	except: pass
	if count = 4 or iterations = 20

the problem is that when count = 4 m_Switch[4-1] have no value, so i use 
the try..except.

Is there a better solution to solve this problem? and, generally 
speaking, the try..except block slow down the execution of the program or 
not?

Thank you in advance
Nico
	



More information about the Python-list mailing list