Kinne, J.
1 *360£ 3 *359I. Our conclusion in this case requires the consideration of but one question, which we deem decisive of plaintiff’s rights. The defendant pleaded a statute of the state of Illinois, which provides: “No person or minor shall climb, jump, step, stand upon, cling to or in any way attach himself to any locomotive engine or car, either stationary or in motion, upon any part of the track of any railroad, unless in so doing he shall be acting in compliance with law, or by permission, under the lawful rules and regulations of the corporations then owning and managing such railroads.” Hurd’s Rev. St. 1891, chapter 114, section 79. Another section provides for the imposition of a fine for a violation of the act. Id. section 81. Plaintiff cannot recover in this action if his own negligence contributed to produce the injuries of which he complains. If such injuries were received as the direct result of a violation of the statute of the state of Illinois, then it must be held that his act in attempting to mount the moving train was, as a matter of law, negligence, which precludes his recovery. One may not be guilty of contributory negligence who receives an injury while he is engaged in an act in violation of law. Gross v. Miller, 95 Iowa, 72 (61 N. W. Rep. 385); Schmid v. Humphrey, 48 Iowa, 652; Van Horn v. Railway Co., 63 Iowa, 68 (18 N. W. Rep. 679). The test is, was the unlawful act the proximate cause of the accident, or injury? If so, he cannot recover. Beach, Contrib. Neg. sections 45-47; 4 Am. & Eng. Enc. Law, p. 50; Gross v. Miller, 93 Iowa, 72 *360(61 N. W. Rep. 385). In other words, if there was such a relation or conneption between the accident and the act of violating the statute of the state of Illinois, on part of the plaintiff, as to cause, or help to cause, the accident, then he was guilty of contributory negligence, as a matter of - law. Gross v. Miller, 93 Iowa, 72 (61 N. W. Rep. 385); Van Horn v. Railway Co., 63 Iowa, 68 (18 N. W. Rep. 679); Schmid v. Humphrey, 48 Iowa, 652; Gribble v. City of Sioux City, 38 Iowa, 390. It is said in Herman v. Railway Co., 79 Iowa, 162 (44 N. W. Rep. 299), in speaking of an instruction: “This instruction is conceded to be correct, because, by section 2, chapter 148, Laws Sixteenth General Assembly, it would have been a misdemeanor for plaintiff to jump from the train while it was in motion, and, under such a state of facts, the law would conclusively presume that the injury was the result of his own negligence.” The statute in this state relating to getting on and off moving trains is, in substance, like that of Illinois, above quoted. In Roben v. Railway Co., 74 Iowa, 732 (34 N. W. Rep. 621), it was, in effect, held that, under the statute of this state, if the act of an injured party in getting off of a train was a misdemeanor, she could not recover. The same rule is recognized in Galloway v. Railway Co., 87 Iowa, 466 (54 N. W. Rep. 447). The failure to comply with a duty imposed by statute, or ordinance, is usually held to be negligence, as a matter of law. Smith v. Trader’s Exchange (Wis.) (64 N. W. Rep. 1041). This might be otherwise if the act of the one who inflicted the wrong was wantonly or wilfully done. Unless, then, plaintiff has shown that, in attempting to mount the moving train, he was “acting in compliance with law, or by permission,, under the lawful rules and regulations of the” defendant company, his act will prevent his recovery.
*361II. The claim, of plaintiff is that he had the “permission of the conductor of the train, or, being directed by him (which amounts to the same thing), had a right to infer that he was acting in compliance with the rules and regulations of the defendant company.” There is nothing in the record to show what the “lawful rules and regulations” of the defendant were. It cannot be assumed that they were such as to authorize trainmen to advise passengers to violate the law of the state, especially when such violation was likely to be followed by an injury to the passenger. Nor do we agree with counsel for the plaintiff that it was incumbent upon the defendant to plead and prove these rules and regulations. Plaintiff was prima facie acting in violation of the law in attempting to board the moving cars. If he was, in so doing, acting in compliance with law, or by permission, under the lawful rules and regulations of the defendant, it was incumbent upon him to establish that fact. He has not done so, and, it seems to us, is in no position to recover, until he, by proper proof, brings himself within the provisions of the statute which excuse his act in attempting to mount the moving cars. This court said, in the Raben Case: “The burden was on plaintiff to prove that the circumstances of the occurrence were such that she was entitled to recover for the injury she sustained, and the question of her right to recover depends upon whether her own act was lawful. It follows, necessarily, that she is not entitled to recover without proof that she was acting lawfully at the time.” Our conclusion renders it unnecessary that we consider other questions argued. — Reversed.