Review my Code!

priest170234

New Member
Reaction score
0
Okay, I tried to code this myself. (Perhaps the first time I am coding myself, without help). Review this for me!
This is a function to check whether a number is prime or not.

Definition of Prime number: A number whose factors are 1 and itself
Numbers less than or equal to 1 are not prime.

JASS:
scope CheckPrime
    globals 
        integer int                 // Constant, does not change at ALL until checked = false
        integer int_2               // Changes
        boolean checked = false
        boolean isPrime
    endglobals

    function CheckPrime takes integer number returns boolean
        if(number<=1) then
            call BJDebugMsg("Please enter a value larger than 1!")
            set isPrime = false
        else
            ////////////////////////////////////////////
            if(checked == false) then
                set checked = true
                set int = number
            endif
            ////////////////////////////////////////////
            set int_2 = number
        
            if (ModuloInteger(int, int_2) == 0) and (int != int_2) then // Divisible, and int not equal to int_2, NOT PRIME
                set int_2 = 0
            endif
        
            if (int_2 == 0) then        // If Its not a Prime Number
                call BJDebugMsg(I2S(int)+" is NOT Prime!") 
                set checked = false
                set isPrime = false
            else                        // Checking...
                if(int_2-1 == 1) then   // If the next number becomes 1, and so far it still prime, then the number IS PRIME!
                    call BJDebugMsg(I2S(int)+" IS Prime!") 
                    set checked = false
                    set isPrime = true
                else
                    set int_2 = int_2 - 1
                    call CheckPrime(int_2)
                endif
            endif
        endif
        return isPrime
    endfunction

endscope
 

BlackRose

Forum User
Reaction score
239
JASS:
.
        if(isPrime == true) then
            return true
        else
            return false
        endif


Can simply become [ljass]return isPrime[/ljass].

I also suggest you drop that header style, it looks terrible! May I also suggest you add a space after each [ljass]//[/ljass]? It looks neater.
 

DioD

New Member
Reaction score
57
JASS:
int_2-1 == 1

vs
JASS:
int_2 == 2


and what is PRIME and what this code doing, i personally dont understand it.
 

priest170234

New Member
Reaction score
0
I stated in the Description.

PRIME is a number whose factors is ONLY itself and 1 where integers below 2 are not considered prime.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top